package com.jiuqian.common.core.util;

import com.jiuqian.common.core.Result;
import com.jiuqian.common.core.exception.BusinessException;

public final class ResponseUtil {

	private static final String FAULT_CODE = "500";
	private static final String SUCCESS_CODE = "200";

	private static final String SUCCESS_MSG = "OK";
	private static final String FAULT_MSG = "服务器内部错误";
	private static final String UNKNOWN_MSG = "服务器内部未知错误";

	public static <T> Result<T> getBusinessResult(BusinessException ex) {
		return new Result<T>(ex.getXCode(), ex.getMessageWithoutCode());
	}

	public static <T> Result<T> getFaultResult() {
		return new Result<T>(FAULT_CODE, FAULT_MSG);
	}

	public static <T> Result<T> getSuccessResult(T obj) {
		return new Result<T>(SUCCESS_CODE, SUCCESS_MSG, obj);
	}

	public static <T> Result<T> getUnknownResult() {
		return new Result<T>(FAULT_CODE, UNKNOWN_MSG);
	}

}
